package com.frx.leetoffer.binarytree;

import java.util.HashMap;
import java.util.Map;

/**
 * @author ：frx
 * @date ：Created in 2019/11/18 22:12
 * @description：输出一个二叉树某个节点中序遍历的下一个节点
 * @modified By：
 * @version: ToDO
 */
public class NextTreeNode {

    public static void main(String[] args){
        Map<String,String> map = new HashMap<>(16);
    }
    public TreeLinkNode getNext(TreeLinkNode pNode){

        if (pNode.right != null){
            TreeLinkNode node = pNode.right;
            while (node.left != null){
                node = node.left;
            }
            return node;
        } else {
            while (pNode.next != null){
                TreeLinkNode next = pNode.next;
                if (next.left == pNode){
                    return next;
                }
                pNode = next;
            }
        }

        return null;
    }


    static class TreeLinkNode{
        int val;
        TreeLinkNode left = null;
        TreeLinkNode right = null;
        TreeLinkNode next = null;
        TreeLinkNode(int val){
            this.val = val;
        }
    }

}
